<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CompanyUser extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('company_user', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '公司用户表', 'id' => 'id', 'signed' => false]);
        $table->addColumn('company_id', 'integer', ['default' => 0, 'limit' => 11, 'comment' => '公司id', 'signed' => false])
                ->addColumn('username', 'string', ['default' => '', 'limit' => 50, 'comment' => '用户名'])
                ->addColumn('password', 'string', ['default' => '', 'limit' => 255, 'comment' => '密码'])
                ->addColumn('head_img', 'string', ['default' => '', 'limit' => 255, 'comment' => '头像'])
                ->addColumn('phone', 'string', ['default' => '', 'limit' => 11, 'comment' => '手机号'])
                ->addColumn('email', 'string', ['default' => '', 'limit' => 50, 'comment' => '邮箱'])
                ->addColumn('login_num', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '登录次数'])
                ->addColumn('last_login_ip', 'string', ['default' => '', 'limit' => 50, 'comment' => '最后登录IP'])
                ->addColumn('last_login_time', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '最后登录时间'])
                ->addColumn('sort', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '排序'])
                ->addColumn('status', 'integer', ['default' => 1, 'limit' => 1, 'comment' => '状态：1启用 2禁用'])
                ->addColumn('is_super', 'integer', ['default' => 0, 'limit' => 1, 'comment' => '是否超级管理员:0否 1是'])
                ->addColumn('create_time', 'integer', ['default' => null, 'limit' => 10, 'comment' => '创建时间'])
                ->addColumn('update_time', 'integer', ['default' => null, 'limit' => 10, 'comment' => '更新时间'])
                ->addColumn('delete_time', 'integer', ['default' => null, 'limit' => 10, 'comment' => '删除时间'])
                ->addIndex('company_id', ['name' => 'idx_company_id'])
                ->addIndex('username', ['name' => 'idx_username'])
                ->addIndex('phone', ['name' => 'idx_phone'])
                ->addIndex('username',['unique' => true])
                ->addIndex('phone',['unique' => true])
                ->create();
    }
}
